{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "733107c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6d1a46e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.7927133 , -0.3619478 , -1.01307995],\n",
       "       [ 0.50406305, -1.23408778, -2.12734316],\n",
       "       [ 0.89454197,  2.32297144,  1.28166672],\n",
       "       [-0.83046725, -0.36418292, -0.17003868],\n",
       "       [-0.28143564, -0.35953702,  0.76874349],\n",
       "       [-0.0196437 ,  0.75745877, -1.10110841]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.random.randn(6,3)\n",
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3e33f126",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(6, 3)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1ecac768",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-0.3619478 , -1.23408778,  2.32297144, -0.36418292, -0.35953702,\n",
       "        0.75745877])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr[:,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5b5666fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.7927133 ,  0.50406305,  0.89454197, -0.83046725, -0.28143564,\n",
       "        -0.0196437 ],\n",
       "       [-0.3619478 , -1.23408778,  2.32297144, -0.36418292, -0.35953702,\n",
       "         0.75745877],\n",
       "       [-1.01307995, -2.12734316,  1.28166672, -0.17003868,  0.76874349,\n",
       "        -1.10110841]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "66241dcb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2-D case\n",
    "# We can think of a 2-D Numpy array as a rectangle, which, if we look at the printout of such an array,\n",
    "# is oriented as follows:\n",
    "#  Axis 0 increases with the rows - we could think of this as the height axis of our rectangle.\n",
    "#  Axis 1 increases with the columns - we could think of this as the width axis of our rectangle\n",
    "# if we apply the transpose, then the axes get swapped, i.e. axix 0 becomes axis 1 and vice versa. \n",
    "# if we pick up the mental model of our rectangle from above, this means:\n",
    "#  (axis 0 -> axis 1): what was on top is now on the left, what was at the bottom is now on the right\n",
    "#  (axis 1 -> axis 0): what was on the left is now on top,what was one the right is now at the bottom\n",
    "# Maybe we should also keep in mind what this is not: Namely, this is not the same as a rotation by 90 degrees\n",
    "# (which would require an additional reversal of the values along one axis)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "853ccd8f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  1],\n",
       "        [ 2,  3]],\n",
       "\n",
       "       [[ 4,  5],\n",
       "        [ 6,  7]],\n",
       "\n",
       "       [[ 8,  9],\n",
       "        [10, 11]]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array_3d = np.array([\n",
    "    [[ 0,  1],\n",
    "     [ 2,  3]],\n",
    "\n",
    "    [[ 4,  5],\n",
    "     [ 6,  7]],\n",
    "\n",
    "    [[ 8,  9],\n",
    "     [10, 11]]\n",
    "])\n",
    "\n",
    "array_3d.shape = (3, 2, 2)\n",
    "array_3d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "8bf0b6a6",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  4,  8],\n",
       "        [ 2,  6, 10]],\n",
       "\n",
       "       [[ 1,  5,  9],\n",
       "        [ 3,  7, 11]]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array_3d.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "18f4b600",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr2d = np.arange(4).reshape((2,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "46c2ec96",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1],\n",
       "       [2, 3]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr2d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "412417f3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 2],\n",
       "       [1, 3]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr2d.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d4f4fcb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6c7e71ea",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (2266369656.py, line 14)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[10], line 14\u001b[1;36m\u001b[0m\n\u001b[1;33m    if we pick up the mental model of our cuboid from above, this means:\u001b[0m\n\u001b[1;37m          ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 3-D case\n",
    "# We can probably still gain a visual mental model for 3-D case if we think of our array as a cuboid, but it may\n",
    "# get harder for more dimensions. if we look at the printout of the 3-D Numpy array and its transpose from your\n",
    "# question, we can see the following:\n",
    "#     Axis 0 is shown as a stack of 2-D slices - we could think of this as the depth axis of our cuboid, e.g.\n",
    "#     with the first slice in the back and the last slice in the front.\n",
    "#     Axis 1 increases with the rows in each slice, axis 2 increases with the columns in each slice(\n",
    "#     just as axes 0 and 1 in the 2-D case) - we could think of these as the height and width axes of our cuboid.\n",
    "# if we apply the transpose, then, as already mentioned, the order of axes gets reversed. In the 3-D case, this\n",
    "# means:\n",
    "#     Axis 0 becomes axis 2.\n",
    "#     Axis 2 become axis 0.\n",
    "#     Axis 1 stays in place.\n",
    "if we pick up the mental model of our cuboid from above, this means:\n",
    "    (axis 0 -> axis 2): what was in the back is now on the left, what wa in fr"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
